<template>
	<view style="padding-bottom: 140rpx;">
		<view class="header">
			<u-swiper :autoplay='false' :list="goodsInfo.images" height='750' border-radius='0' mode='number'
				indicator-pos='bottomRight'></u-swiper>
			<view class="nav-bar">
				<view class="left" @click="back">
					<image src="../../../../static/imgs/backicon.png" mode=""></image>
				</view>
				<view class="right" @click="showShare=true">
					<image src="../../../../static/imgs/fengxiangbg.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="goodsInfo">
			<view class="title">
				{{goodsInfo.name}}
			</view>
			<view class="price-box">
				<view class="left">
					<view class="dzh" v-if="$store.state.userInfo.user_level==0">
						<text style="font-size: 24rpx;font-weight: normal;">¥</text>{{goodsInfo.i_price}}
					</view>
					<view class="dzh" v-else>
						<text style="font-size: 24rpx;font-weight: normal;">¥</text>{{goodsInfo.i_price}}
					</view>
					<view class="dzq">
						¥{{goodsInfo.market_price}}
					</view>
				</view>
				<view class="right">
					热销{{goodsInfo.sales_sum}}件
				</view>
			</view>
			
			<view class="priceBox">
				<view class="rel-price" v-if='$store.state.userInfo.user_level == 0'>
					¥<text>{{(Number(goodsInfo.i_price)-Number(goodsInfo.use_welfare_fund)).toFixed(2)}}</text>
				</view>
				<view class="rel-price" v-else>
					¥<text>{{(Number(goodsInfo.i_vip_price)-Number(goodsInfo.use_welfare_fund)).toFixed(2)}}</text>
				</view>
				<view class="fl-price">
					+{{goodsInfo.use_welfare_fund}} 福利金
				</view>
			</view>
		<!-- 	<view class="song">
				送{{goodsInfo.give_travel_found}}旅游基金
			</view> -->
		</view>
		<view class="comment">
			<view class="top">
				<view class="text">
					商品评价(0)
				</view>
				<view class="all">
					查看全部<u-icon name="arrow-right" color="#666666" size="28"></u-icon>
				</view>
			</view>
			<!-- <view class="content">
				<view class="head">
					<image class="headPic" src="../../../../static/imgs/del/del.png" mode=""></image>
					<view class="info">
						<text class="name">小胖墩</text>
						<text class="date">12/17 15 :19</text>
					</view>
				</view>
				<view class="bottom">
					<view class="text">
						水磨沟景区位于广元市朝天区，地处秦岭山脉与大巴山脉之间，国家AAAA级旅游景区，森林覆盖率82%，是名副其实的天然氧吧。
					</view>
					<view class="imgs">
						<image src="../../../../static/imgs/del/del.png" mode=""></image>
					</view>
				</view>
			</view> -->
			<view class="content">
				<view class="nocont">
					<image src="../../../../static/imgs/zanwupl.png" mode=""></image>
				</view>
				<view class="tip">暂无评论</view>
			</view>
		</view>
		<view class="detail">
			<view class="lable">
				商品详情
			</view>
			<view class="content" v-html="goodsInfo.goods_content">
			</view>
		</view>
		<view class="tab-bar">
			<view class="kefu" @click="navTo('../../../mine/kefu/kefu')">
				<u-icon name="kefu-ermai" color="#333333" size="44"></u-icon>
				<text>客服</text>
			</view>
			<view class="collect" @click="collectFn">
				<u-icon name="star" color="#333333" size="44" v-if="!isCollect"></u-icon>
				<u-icon name="star-fill" color="#FF0000" size="44" v-else></u-icon>
				<text>收藏</text>
			</view>
			<view class="goCart" @click="addCart">
				加入购物车
			</view>
			<view class="buy" @click="showBuy=true">
				立即购买
			</view>
		</view>

		<u-popup v-model="showBuy" :closeable='true' mode="bottom">
			<view class="buyBox">
				<view class="goodsBox">
					<image src="../../../../static/imgs/del/del.png" mode=""></image>
					<view class="info">
						<view class="title">
							{{goodsInfo.name}}
						</view>
						<view class="id">
							规格：{{goodsInfo.ware_qd}}
						</view>
						<view class="price" v-if="$store.state.userInfo.user_level==0">
							<text style="font-weight: normal;font-size: 24rpx;">¥</text>{{goodsInfo.i_price}}
						</view>
						<view class="price" v-else>
							<text style="font-weight: normal;font-size: 24rpx;">¥</text>{{goodsInfo.i_price}}
						</view>
					</view>
				</view>
				<view class="number">
					<text>购买数量</text>
					<u-number-box v-model="goodsNum" :min="1" @change="valChange"></u-number-box>
				</view>
				<view class="btns">
					<view class="goCart" @click="addCart">
						加入购物车
					</view>
					<view class="goBuy" @click="buyNow">
						立即购买
					</view>
				</view>
			</view>
		</u-popup>

		<u-popup v-model="showShare" mode="bottom" border-radius="16" :closeable='true'>
			<view class="sharePop">
				<view class="title">
					分享到
				</view>
				<view class="share-ul">
					<view class="share-li">
						<image src="../../../../static/imgs/weixinhy.png" mode=""></image>
						<text>微信好友</text>
					</view>
					<view class="share-li">
						<image src="../../../../static/imgs/pengyouq.png" mode=""></image>
						<text>朋友圈</text>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	export default {
		data() {
			return {
				isCollect: false, // 是否收藏
				goodsNum: 1, // 默认购买数量
				showShare: false,
				showBuy: false,
				goodsId: '', // 商品规格id
				goodsInfo: '', // 商品详情
			}
		},
		onLoad(option) {
			this.goodsId = option.id
			this.getDetail()
			this.getCollect()
		},
		methods: {
			// 立即购买
			async buyNow() {
				let {
					goodsId,
					goodsNum
				} = this
				let res = await myRequest.addMycart({
					sku_id: goodsId.toString(),
					goods_num: goodsNum.toString()
				})
				if (res.status) {
					this.showBuy = false
					this.$store.commit('changeCartId', res.cart_id)
					uni.navigateTo({
						url: '../order/order?cart_id='+res.cart_id
					})
				}
			},
			// 加入购物车
			async addCart() {
				let {
					goodsNum,
					goodsId
				} = this
				let res = await myRequest.addMycart({
					sku_id: goodsId.toString(),
					goods_num: goodsNum.toString()
				})
				if (res.status) {
					this.showBuy = false
					uni.showToast({
						title: '添加成功'
					})
				}
			},
			// 匹配是否收藏
			async getCollect() {
				let res = await myRequest.getMyCollect()
				if (res.status) {
					res.data.forEach(item => {
						if (item.goods_sku_id == this.goodsId) {
							this.isCollect = true
							return
						}
					})
				}
			},
			// 收藏
			async collectFn() {
				let res = await myRequest.addCollect({
					goods_sku_id: this.goodsId
				})
				if (res.status) {
					uni.showToast({
						title: '收藏成功'
					})
					this.getCollect()
				}
			},
			// 商品详情
			async getDetail() {
				let {
					goodsId
				} = this
				let res = await myRequest.getGoodsDetail({
					goods_sku_id: goodsId
				})
				if (res.status) {
					res.data[0].goods_content = res.data[0].goods_content.replace(new RegExp('//sku-market', "g"),
						'http://sku-market'),
						this.goodsInfo = res.data[0]
				}
			},
			valChange(e) {
				this.goodsNum = e.value
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-swiper-wrap {
		width: 100%;
		height: 100%;
	}

	.header {
		width: 100%;
		height: 750rpx;
		background: #FFFFFF;
		position: relative;
		z-index: 1;

		.nav-bar {
			width: 100%;
			height: 88rpx;
			padding: 0 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: fixed;
			top: var(--status-bar-height);

			.left,
			.right {
				image {
					width: 60rpx;
					height: 60rpx;
				}
			}
		}
	}

	.goodsInfo {
		width: 100%;
		height: auto;
		background-color: #FFFFFF;
		padding: 0 28rpx 14rpx;

		.title {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 600;
			line-height: 22px;
			color: #333333;
			padding-top: 14rpx;
		}
		
		.priceBox {
			width: fit-content;
			width: -webkit-fit-content;
			width: -moz-fit-content;
			display: flex;
			margin-top: 24rpx;
		
			.rel-price {
				height: 44rpx;
				width: fit-content;
				width: -webkit-fit-content;
				width: -moz-fit-content;
				background: linear-gradient(180deg, #FBE9B9 0%, #FDE6B8 100%);
				border-radius: 8rpx 0px 0px 8rpx;
				padding: 0 6rpx;
				font-size: 24rpx;
				font-family: Arial;
				font-weight: 400;
				line-height: 44rpx;
				color: #333333;
		
				text {
					font-size: 32rpx;
					font-weight: bold;
					margin-left: 4rpx;
				}
			}
		
			.fl-price {
				height: 44rpx;
				width: fit-content;
				width: -webkit-fit-content;
				width: -moz-fit-content;
				background: #333333;
				border-radius: 0px 8rpx 8rpx 0px;
				font-size: 24rpx;
				font-family: Arial;
				font-weight: 400;
				color: #FBE8B8;
				line-height: 44rpx;
				padding: 0 6rpx;
			}
		}

		.price-box {
			margin-top: 16rpx;
			display: flex;
			align-items: center;

			.left {
				display: flex;
				align-items: center;

				.dzh {
					font-size: 36rpx;
					font-family: Arial;
					font-weight: bold;
					color: #FB4F4B;
				}

				.dzq {
					margin-left: 16rpx;
					font-size: 28rpx;
					font-family: Segoe UI;
					font-weight: 400;
					color: #999999;
					text-decoration: line-through;
				}
			}

			.right {
				margin-left: auto;
				font-size: 28rpx;
				font-family: Segoe UI;
				font-weight: 400;
				color: #999999;
			}
		}
		
	}

	.comment {
		width: 710rpx;
		height: auto;
		background: #FFFFFF;
		border-radius: 16rpx;
		margin: 20rpx auto 0;
		padding: 0 20rpx 10rpx;

		.top {
			width: 100%;
			height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.text {
				font-size: 32rpx;
				font-family: Segoe UI;
				font-weight: 400;
				color: #333333;
			}

			.all {
				font-size: 28rpx;
				font-family: Segoe UI;
				font-weight: 400;
				color: #666666;
			}
		}

		.content {

			.head {
				width: 100%;
				height: 120rpx;
				display: flex;
				align-items: center;

				.headPic {
					width: 92rpx;
					height: 92rpx;
					border-radius: 50%;
				}

				.info {
					margin-left: 16rpx;
					display: flex;
					flex-direction: column;

					.name {
						font-size: 28rpx;
						font-family: Segoe UI;
						font-weight: 400;
						color: #333333;
					}

					.date {
						font-size: 24rpx;
						font-family: Segoe UI;
						font-weight: 400;
						color: #999999;
					}
				}
			}

			.bottom {
				.text {
					font-size: 28rpx;
					font-family: Segoe UI;
					font-weight: 400;
					color: #333333;
				}

				.imgs {
					margin-top: 24rpx;
					display: flex;
					flex-wrap: wrap;
					justify-content: space-between;

					image {
						&:only-child {
							width: 264rpx;
							height: 284rpx;
						}

						margin-bottom: 4rpx;
						width: 216rpx;
						height: 216rpx;
					}
				}
			}

			.nocont {
				width: 228rpx;
				height: 178rpx;
				margin: 0 auto;

				image {
					width: 228rpx;
					height: 178rpx;
				}
			}

			.tip {
				text-align: center;
				font-size: 24rpx;
				font-family: Segoe UI;
				font-weight: 400;
				color: #333333;
			}
		}
	}

	.detail {
		width: 710rpx;
		height: auto;
		margin: 34rpx auto 0;
		background-color: #FFFFFF;
		border-radius: 16rpx;

		.lable {
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			font-size: 32rpx;
			font-family: Segoe UI;
			font-weight: 400;
			color: #333333;
			padding-left: 26rpx;
		}
	}

	.tab-bar {
		width: 100%;
		height: 120rpx;
		background-color: #FFFFFF;
		position: fixed;
		bottom: 0;
		display: flex;
		align-items: center;
		padding-left: 70rpx;
		padding-right: 28rpx;

		.kefu,
		.collect {
			display: flex;
			flex-direction: column;
			align-items: center;

			text {
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}

		.collect {
			margin-left: 70rpx;
		}

		.goCart,
		.buy {
			width: 200rpx;
			height: 76rpx;
			border-radius: 16rpx;
			font-size: 32rpx;
			font-family: Segoe UI;
			font-weight: 400;
			color: #FFFFFF;
			line-height: 76rpx;
			text-align: center;
		}

		.goCart {
			background: linear-gradient(180deg, #FBE57A 0%, #FF7700 100%);
			margin-left: 70rpx;
		}

		.buy {
			background: linear-gradient(180deg, #50A3FE 0%, #3064FC 100%);
			margin-left: auto;
		}
	}

	.buyBox {

		.goodsBox {
			display: flex;
			padding: 28rpx 28rpx 0;

			image {
				width: 200rpx;
				height: 200rpx;
			}

			.info {
				margin-left: 16rpx;
				width: 64%;

				.title {
					font-size: 30rpx;
					font-family: Segoe UI;
					font-weight: 400;
					color: #333333;
				}

				.id {
					margin-top: 16rpx;
					font-size: 28rpx;
					font-family: Segoe UI;
					font-weight: 400;
					color: #999999;
				}

				.price {
					margin-top: 14rpx;
					font-size: 36rpx;
					font-family: PingFang SC;
					font-weight: 600;
					color: #FB4F4B;
				}
			}
		}

		.number {
			width: 694rpx;
			height: 88rpx;
			margin: 0 auto;
			display: flex;
			align-items: center;
			justify-content: flex-end;

			text {
				font-size: 28rpx;
				font-family: Segoe UI;
				font-weight: 400;
				color: #666666;
				margin-right: 64rpx;
			}
		}

		.btns {
			padding: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.goCart,
			.goBuy {
				width: 340rpx;
				height: 76rpx;
				border-radius: 8px;
				line-height: 76rpx;
				text-align: center;
				font-size: 32rpx;
				font-family: Segoe UI;
				font-weight: 400;
				color: #FFFFFF;
			}

			.goCart {
				background: linear-gradient(180deg, #FBE57A 0%, #FF7700 100%);
			}

			.goBuy {
				background: linear-gradient(180deg, #50A3FE 0%, #3064FC 100%);
			}
		}
	}

	.sharePop {
		padding: 0 28rpx;

		.title {
			width: 100%;
			height: 100rpx;
			text-align: center;
			line-height: 100rpx;
			font-size: 34rpx;
			font-family: Segoe UI;
			font-weight: 400;
			color: #333333;
			border-bottom: 2rpx solid #F2F2F2;
		}

		.share-ul {
			width: 100%;
			height: 240rpx;
			display: flex;
			align-items: center;

			.share-li {
				flex: 1;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;

				image {
					width: 88rpx;
					height: 88rpx;
				}

				text {
					margin-top: 20rpx;
					font-size: 28rpx;
					font-family: Segoe UI;
					font-weight: 400;
					color: #333333;
				}
			}
		}
	}
	
	/deep/ .content img {
		max-width: 710rpx !important;
		height: auto !important;
	}

	/deep/ .uicon-close {
		top: -16rpx !important;
	}

	/deep/ .u-close--top-right {
		right: 24rpx !important;
	}

	/deep/ .ssd-module-wrap {
		max-width: 710rpx !important;
	}

	/deep/ .ssd-module {
		max-width: 710rpx !important;
		height: auto !important;
	}

	/deep/ .ssd-widget-pic img{
		max-width: 710rpx !important;
		height: auto !important;
	}

	/deep/ .ssd-widget-text {
		max-width: 710rpx !important;
		height: auto !important;
	}
</style>
